#ifndef TEXTEDIT_H
#define TEXTEDIT_H
#include <QTextEdit>
#include <QFile>

class TextEdit : public QTextEdit
{
    Q_OBJECT
public:
    TextEdit(QWidget *parent = nullptr);
    ~TextEdit();

    void initNewDoc();
    bool loadDocument(const QString& fileName);

    QString getDocName() const;
    QString getFilePath() const;

    bool saveDoc();
    bool saveAsDoc();

protected:
    void closeEvent(QCloseEvent* event) override;
    //void keyPressEvent(QKeyEvent *event) override;

private slots:
    void setWindowModify();

private:
    void initOpenDoc(const QString& fileName);
    bool writeToDoc(const QString& fileName);
    bool promptSave();                              //提示保存
    //void handleListReturn();

private:
    QString docName;
    QString filePath;
    static int docNo;
};

#endif // TEXTEDIT_H
